require((['/js/config.js']), () => {
    require((['request', 'template', 'swiper', 'header', 'footer']), (request, template, Swiper) => {
        class Indexbody {
            constructor(request) {
                this.index_shop_show()
                this.nav_swiper()
            }
            index_shop_show() { //首页中部图片展示
                request.get_index_shop().then((resp) => {
                    if (resp.code === 200) {
                        const list = resp.body
                        $('#shop_show_ul').html(template('shop_show_li', list))
                    }
                })
            }
            index_swiper(){ //获取需要轮播的数据
                return  new Promise((t)=>{
                    request.get_index_swiper().then((resp)=>{
                        if(resp.code===200){
                            var newlist = resp.body
                            $('#my_swiper_template_title').html(template('my_swiper_template',newlist))
                        }
                        t()
                    })
                }) 
            }
            nav_swiper() { //轮播图swiper
                this.index_swiper().then(()=>{
                    var mySwiper = new Swiper('.swiper-container', {
                        loop: true, // 循环模式选项
                        effect: 'fade', //淡入
    
                        // 如果需要分页器
                        pagination: {
                            el: '.swiper-pagination',
                            clickable: true,
                        },
    
                        // 如果需要前进后退按钮
                        navigation: {
                            nextEl: '.swiper-button-next',
                            prevEl: '.swiper-button-prev',
                        },
                        autoplay: { //自动播放
                            autoplay: true,
                            delay: 5000,
                        }
    
    
                    })
                    mySwiper.el.onmouseenter = function () {
                        mySwiper.autoplay.stop();
                    }
                    mySwiper.el.onmouseleave = function () {
                        mySwiper.autoplay.start();
                    }
                })
            }
        }

        new Indexbody()


    })
});